#include <iostream>

void staticCast()
{
    char a = 'a';
    int b = static_cast<char>(a); //正确，将char型数据转换成int型数据

    double *c = new double;
    void *d = static_cast<void *>(c); //正确，将double指针转换成void指针

    int e = 10;
    const int f = static_cast<const int>(e); //正确，将int型数据转换成const int型数据

    const int g = 20;
    int *h = static_cast<int *>(&g); //编译错误，static_cast不能转换掉g的const属性
}

int main(int argc, char const *argv[])
{
    // 没有运行时检查来保证数据转换安全
    // 1、void->
    // 2、改变通常的标准转换
    // 3、避免出现的多种转换歧义
    // std::static_cast<>
    const int cc = 10;
    printf("%d\n", cc);
    float cf = static_cast<float>(cc);
    cf = 12.36;
    printf("%f\n", cf);

    // 类型检查
    // std::dynamic_cast<>

    const int cc = 10;
    printf("%d\n", cc);
    float cf = static_cast<float>(cc);
    cf = 12.36;
    printf("%f\n", cf);

    return 0;
}
